package kit.edu.lego.gruppe3.levels.door;

import kit.edu.lego.gruppe3.ComponentsRepository;
import kit.edu.lego.gruppe3.LegoMain;
import kit.edu.lego.gruppe3.levels.LevelSelector;
import kit.edu.lego.gruppe3.levels.LevelSelector.Level;
import lejos.robotics.subsumption.Behavior;

public class DoreEnd implements Behavior{

	@Override
	public void action() {
		LevelSelector.getInstance().setCurrentLevel(Level.treeArea);
		ComponentsRepository.getInstance().getRobotPilot().stop();
		
		ComponentsRepository.getInstance().getRobotPilot().travel(12f);
		ComponentsRepository.getInstance().getRobotPilot().rotate(-100);
		ComponentsRepository.getInstance().getRobotPilot().travel(15f);
		ComponentsRepository.getInstance().getRobotPilot().rotate(90);
		
		DoorSolver.closeGate();
		
		DoorSolver.setLevelCleared(true);
		LegoMain.startTreeArea();
	}

	@Override
	public void suppress() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean takeControl() {
		return LevelSelector.getInstance().isDore() &&
			ComponentsRepository.getInstance().getLightSensor().getLightValue() > 
			ComponentsRepository.LIGHT_TRASHOLD;
	}

}
